<?php

namespace App\Http\Controllers\VideoApi;

use App\Http\Config\ErrorCode;
use App\Models\video\CommonServer;
use App\Models\video\VideoSettingModel;
use Illuminate\Http\Request;

class CheatingController
{
    public $returnData;

    public function __construct(Request $request)
    {
        /*--- start 跨域测试用 (待删除) ---*/
        header('Access-Control-Allow-Origin: *');                                                                 // 允许任意域名发起的跨域请求
        header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
        header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');
        header('Access-Control-Allow-Headers:x-requested-with,content-type');
        /*--- end 跨域测试用---*/
        if($request->getMethod() == "OPTIONS"){
            $this->returnData = ErrorCode::$admin_enum['fail'];
            return $this->returnData;
        }
        $this->returnData = ErrorCode::$admin_enum['success'];
    }

    //统一返回数据
    public function return_result(array $data, $text = '')
    {
        if(!is_array($data['msg']) && $text && strpos($data['msg'], "%s") !== false){
            $data['msg'] = sprintf($data['msg'], $text);
        }
        return response()->json($data);
    }

    public function getData(Request $request){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $settingData = VideoSettingModel::getFields("review_content", ["mall_id" => $request->mallData["id"]]);
        if(!empty($settingData["reviewContent"])) {
            $data = @json_decode($settingData["reviewContent"], true);
            $data["picUrl"] = isset($data["picId"]) ? $data['picId'] : "";
        }
        if(empty($data)) {
            $data = [
                "name" => "可美 - 自媒体云", "picUrl" => CommonServer::getUrl() . '/uploads/2f0a93d8-8629-4fb7-bacc-31530ef320ca.gif',
                "brief" => "深圳市高新企业。本公司是华南地区腾讯云授权服务中心，成立于2014年，致力于为客户打造一站式采用SaaS云计算技术提供软件功能、硬件运作平台，并负责所有技术服务（包括软件开发、升级、维护、服务器管理、云服务器租赁，云技术产品，SaaS软件等服务）。 我们拥有一支具有多年经验的技术团队，技术领导层均来自云计算、SaaS、大数据等领域的知名技术公司。公司成员年轻化，是一支激情和创造力共存的团队，致力于向客户提供专业、快速、便捷、优质的的售前和售后服务。",
                "email" => "service@wegouer.com", "mobile" => "18924660919", "telPhone" => "0755-33168399",
                "address" => "深圳市南山区西丽街道打石二路1111万科里A栋1408"
            ];
        }
        $this->returnData["data"] = $data;
        return $this->return_result($this->returnData);
    }
}
